//https://leetcode.cn/problems/reverse-words-in-a-string/
package codeRandomThoughts.Test151反转字符串中的单词;

import java.util.Arrays;
import java.util.Collections;

public class Solution2 {
    public String reverseWords(String s) {
        //首先用trim()删除字符串头部和尾部的空白符号
        String[] words = s.trim().split(" +");

        //反转String[]数组
        Collections.reverse(Arrays.asList(words));

        //连接words
        return String.join(" ",words);
    }
}
